﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Zeta.Common.Plugins;
using System.Reflection;
using Zeta.Common.Xml;

namespace KadalaSpree.XCore
{
    public abstract class XPlugin : IPlugin
    {
        public XModules Modules { get; set; }

        protected XPlugin() 
        {
            Modules = new XModules();                  
        }

        public string Name { get; set; }
        public Version Version { get; set; }
        public string Author { get; set; }
        public string Description { get; set; }

        public Window DisplayWindow
        {
            get
            {
                if (SettingsXaml == null || SettingsClass == null) return null;
                return Config.GetDisplayWindow(SettingsXaml, SettingsClass, Name);                                    
            }
        }

        public XmlSettings SettingsClass { get; set; }
        public string SettingsXaml { get; set; }

        public bool Equals(IPlugin other) { return (other.Name == Name) && (other.Version == Version); }

        public virtual void OnInitialize() { Modules.OnInitialize(); }
        public virtual void OnEnabled() { Modules.OnEnabled(); }
        public virtual void OnDisabled() { Modules.OnDisabled(); }
        public virtual void OnShutdown() { Modules.OnShutdown(); }
        public virtual void OnPulse() { Modules.Pulse(); }

        public delegate bool DebugConditionDelegate();
        public DebugConditionDelegate DebugCondition { get; set; }
        public bool IsDebug
        {
            get 
            {
                return DebugCondition();
            }
        }
    }

}
